<!-- 员工登录后的添加车辆页面entercar.php -->
<!DOCTYPE html>
<html>

<?php
include('session_client.php'); // 引入客户端会话文件
?>

<head>
  <link rel="shortcut icon" type="image/png" href="assets/img/P.png.png">
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato">
  <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
  <link rel="stylesheet" href="assets/fonts/font-awesome.min.css">
  <link rel="stylesheet" type="text/css" href="assets/css/customerlogin.css">
  <link rel="stylesheet" href="assets/w3css/w3.css">
  <script type="text/javascript" src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
  <script type="text/javascript" src="assets/js/bootstrap.min.js"></script>
  <link rel="stylesheet" type="text/css" media="screen" href="assets/css/clientpage.css" />
</head>

<body>

  <!-- 导航栏 -->
  <?php
  include './nav.php';
  ?>

  <div class="container" style="margin-top: 65px;">
    <div class="col-md-7" style="float: none; margin: 0 auto;">
      <div class="form-area">
        <form role="form" id="carForm" enctype="multipart/form-data">
          <br style="clear: both">
          <h3 style="margin-bottom: 25px; text-align: center; font-size: 30px;"> 请提供您车辆的详细信息。 </h3>

          <div class="form-group">
            <input type="text" class="form-control" id="car_name" name="car_name" placeholder="汽车名称 " required autofocus="">
          </div>

          <div class="form-group">
            <input type="text" class="form-control" id="car_nameplate" name="car_nameplate" placeholder="车辆车牌号" required>
          </div>

          <div class="form-group">
            <input type="text" class="form-control" id="ac_price" name="ac_price" placeholder="AC每公里费用（元）" required>
          </div>

          <div class="form-group">
            <input type="text" class="form-control" id="non_ac_price" name="non_ac_price" placeholder="非AC每公里费用（元）" required>
          </div>

          <div class="form-group">
            <input type="text" class="form-control" id="ac_price_per_day" name="ac_price_per_day" placeholder="AC每天费用（元）" required>
          </div>

          <div class="form-group">
            <input type="text" class="form-control" id="non_ac_price_per_day" name="non_ac_price_per_day" placeholder="非AC每天费用（元）" required>
          </div>

          <div class="form-group">
            <input name="uploadedimage" type="file">
          </div>
          <button type="button" id="submit" name="submit" class="btn btn-success pull-right"> 提交租赁申请</button>
        </form>
        <div id="response-message"></div>
      </div>
    </div>

    <div class="col-md-12" style="float: none; margin: 0 auto;">
      <div class="form-area" style="padding: 0px 100px 100px 100px;">
        <form action="" method="POST">
          <br style="clear: both">
          <h3 style="margin-bottom: 25px; text-align: center; font-size: 30px;"> 我的汽车 </h3>
          <?php
          // 存储会话
          $user_check = $_SESSION['login_client'];
          $sql = "SELECT * FROM cars WHERE car_id IN (SELECT car_id FROM clientcars WHERE client_username='$user_check');";
          $result = mysqli_query($conn, $sql);

          if (mysqli_num_rows($result) > 0) {
          ?>
            <div style="overflow-x:auto;">
              <table class="table table-striped">
                <thead class="thead-dark">
                  <tr>
                    <th></th>
                    <th width="24%"> 名称</th>
                    <th width="15%"> 车牌号 </th>
                    <th width="13%"> AC费用（每公里） </th>
                    <th width="17%"> 非AC费用（每公里）</th>
                    <th width="13%"> AC费用（每天）</th>
                    <th width="17%"> 非AC费用（每天）</th>
                    <th width="1%"> 可用性 </th>
                  </tr>
                </thead>

                <?PHP
                // 输出每一行的数据
                while ($row = mysqli_fetch_assoc($result)) {
                ?>

                  <tbody>
                    <tr>
                      <td> <span class="glyphicon glyphicon-menu-right"></span> </td>
                      <td><?php echo $row["car_name"]; ?></td>
                      <td><?php echo $row["car_nameplate"]; ?></td>
                      <td><?php echo $row["ac_price"]; ?></td>
                      <td><?php echo $row["non_ac_price"]; ?></td>
                      <td><?php echo $row["ac_price_per_day"]; ?></td>
                      <td><?php echo $row["non_ac_price_per_day"]; ?></td>
                      <td><?php echo $row["car_availability"]; ?></td>
                    </tr>
                  </tbody>
                <?php } ?>
              </table>
            </div>
            <br>
          <?php } else { ?>
            <h4>
              <center>0 可用汽车</center>
            </h4>
          <?php } ?>
        </form>
      </div>
    </div>
  </div>
  <script>
    $(document).ready(function() {
      // AJAX提交表单数据
      $("#submit").click(function() {
        var formData = new FormData($("#carForm")[0]);

        $.ajax({
          type: "POST",
          url: "entercar1.php",
          data: formData, // 表单序列化
          contentType: false,
          processData: false,
          success: function(response) {
            // 处理返回的数据，更新页面
            $("#response-message").html(response);
          }
        });
      });
    });
  </script>
</body>

<footer class="site-footer">
  <div class="container">
    <hr>
    <div class="row">
      <div class="col-sm-6">
        <h5>© <?php echo date("Y"); ?> 租车服务</h5>
      </div>
    </div>
  </div>
</footer>

</html>